package dfsdfsadf;

import java.util.TreeSet;
public class TreeSetTest4
{
    public static void main(String[] args)
        {
            TreeSet<X> set = new TreeSet<X>();
            X x1 = new X(5);
            X x2 = new X(-3);
            X x3 = new X(9);
            X x4 = new X(-2);
            X x5 = new X(15);
           // X x6 = new X(0);
            set.add(x1);
            set.add(x2);
            set.add(x3);
            set.add(x4);
            set.add(x5);
            //set.add(x6);
            System.out.println(set);
            X first = set.first();
            first.count = 20;
            X last = set.last();
            last.count = -2;
            System.out.println(set);
            System.out.println(set.remove(new X(-2)));
            System.out.println(set);
            System.out.println(set.remove(new X(5)));
            System.out.println(set);
        }
}
class X implements Comparable<Object>
{
int count;
private int ii=0;
public X(int count)
{
this.count = count;
}
@Override
public String toString()
{    
	ii++;
	//System.out.println(ii);
return "R[count:" + count + "]";
}
@Override
public boolean equals(Object obj){
if (this == obj){
   return true;
}
if (null != obj && this.getClass() == obj.getClass()){
   X r = (X) obj;
   if (r.count == this.count){
      return true;
   }
}
return false;
}
@Override
public int compareTo(Object o)
{
X r = (X) o;
return count > r.count ? 1 : (count < r.count) ? -1 : 0;
}
}